package com.market.member.service.login;

import cn.hutool.core.util.ObjectUtil;
import com.block.common.constant.AppRspCodeConstant;
import com.block.common.model.dto.LoginReqDTO;
import com.block.common.model.dto.NewMemberDTO;
import com.block.common.service.IMemberCommonService;
import com.block.common.vo.ResponseVo;
import com.block.db.entity.MemberBaseInfo;
import com.block.db.mapper.MemberBaseInfoMapper;
import com.market.member.enums.UserRegTypeEnum;
import com.market.member.enums.UserTypeEnum;
import com.market.member.model.dto.LoginResultDTO;
import com.market.member.service.ILoginTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户联登
 */
@Slf4j
@Service
public class UnionLoginServiceImpl extends ILoginTypeService {

    @Resource
    MemberBaseInfoMapper memberBaseInfoMapper;
    @Autowired
    IMemberCommonService memberCommonService;

    @Override
    public ResponseVo toLogin(LoginReqDTO loginReqDTO) {

        String uid = loginReqDTO.getMobile();

        MemberBaseInfo memberInfo = memberBaseInfoMapper.getMemberInfoByUidLock(Long.valueOf(uid));
        boolean isNewMember = false;
        if (memberInfo == null){
            return new ResponseVo(AppRspCodeConstant.SYS_EXCEPTION, "用户不存在");
        }

        // 登录结果
        LoginResultDTO loginResultDTO = new LoginResultDTO();
        loginResultDTO.setUid(memberInfo.getUid());
        loginResultDTO.setNewMember(isNewMember);
        loginResultDTO.setMemberBaseInfo(memberInfo);

        return new ResponseVo(AppRspCodeConstant.SUCCESS, loginResultDTO);
    }
}
